package org.feluma.sgci.service;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.feluma.sgci.controle.Transporte;
import org.feluma.sgci.util.Testes;


public class Service extends HttpServlet {
	private static final long serialVersionUID = 3L;
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
    	Transporte.setRequest(request);
    	Transporte.setResponse(response);
    	try {
    		RequestDispatcher rd = null;
    		String classe = request.getParameter("classe");
			String metodo = request.getParameter("acao");
			
			Object o = Class.forName(classe).newInstance();
			Method metodoRequerido = o.getClass().getDeclaredMethod(metodo);
			String retorno = (String) metodoRequerido.invoke(o);
			
			rd = request.getRequestDispatcher(retorno);
			rd.forward(request, response);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
    }    
}
